package com.hyt.it.ogt.ks.base;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import com.hyt.model.QuotEditor;

/**
 * @author 林坚丁
 * @date 2020/5/10 21:52
 * @Description
 */
public abstract class BaseController {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());
    /**
     * @param binder ServletRequestDataBinder
     */
    @InitBinder
    public void initBinder(ServletRequestDataBinder binder) {
        /**
         * 自动转换日期类型的字段格式
         */
        binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
        //双引号特殊处理
        binder.registerCustomEditor(String.class, new QuotEditor());
        /**
         * 防止XSS攻击
         */
        //binder.registerCustomEditor(String.class, new StringEscapeEditor());
    }
}
